﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LogHelper;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ConsoleTest
{
    class Program
    {
        private static void log(int i)
        {
            if (i % 5 == 0)
            {
                try
                {
                    int tt = int.Parse("error");
                }
                catch (Exception ex)
                {
                    Log.Error(new MyLogContent(i.ToString(), ex));
                }
            }
            else if (i % 3 == 0)
            {
                Log.Error(new G_Log() { i = i });
            }
            else
            {
                Log.Debug(new MyLogContent(i.ToString(), i.ToString()));
            }
        }

        static void Main(string[] args)
        {
            Log.Init();
            int num = 1000;
            while (true)
            {
                Stopwatch watch = new Stopwatch();
                watch.Start();
                int j = 0;
                ThreadStart t = new ThreadStart(new Action(() =>
                {
                    Console.WriteLine("正在写入...");
                    Parallel.For(0, num, (i) =>
                    {
                        j++;
                        Console.Write(".");
                        if (j % 100 == 0) { Console.WriteLine($"写入第{j}笔..."); }
                        log(i);
                    });
                }));

                Thread thr = new Thread(t);
                thr.Start();
                while (true)
                {
                    if (thr.ThreadState == System.Threading.ThreadState.Stopped)
                    {
                        watch.Stop();
                        break;
                    }
                }
                Console.WriteLine($"\n输出日志{num}条，耗时：{watch.ElapsedMilliseconds}毫秒。\n");

                Console.WriteLine("是否继续？Y/N");
                string jx = Console.ReadLine();
                if (jx.ToUpper().CompareTo("Y") == 0) { continue; }
                else { break; }


            }

            //Console.ReadLine();
        }
    }
}
